<template>
<div>
  <city-header></city-header>
  <city-search :cities="cities"></city-search>
  <city-list :cities="cities" :hotCities="hotCities" :letter="letterIndex" @changeIndex="handleIndex"></city-list>
  <city-alphabet :listIndex="listIndex" :cities="cities" @change="handleLetterClick"></city-alphabet>
</div>
</template>
<script type='text/babel'>
import axios from 'axios'
import CityHeader from './components/Header'
import CitySearch from './components/Search.vue'
import CityList from './components/List.vue'
import CityAlphabet from './components/Alphabet.vue'
export default {
  data () {
    return {
      cities: {},
      hotCities: [],
      letterIndex: 0,
      clientHeight: [],
      listIndex: 0
    }
  },
  created () {},
  mounted () {
    this.getCityInfo()
  },
  methods: {
    getCityInfo () {
      let that = this
      axios.get('/api/city.json').then(that.getCityInfoSucc)
    },
    getCityInfoSucc (res) {
      let resData = res.data
      if (resData.ret && resData.data) {
        let data = resData.data
        this.cities = data.cities
        this.hotCities = data.hotCities
      }
    },
    handleLetterClick (index) {
      this.letterIndex = index
    },
    handleIndex (index) {
      this.listIndex = index
    }
  },
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  }
}
</script>
<style scoped lang="scss" rel="stylesheet/scss"></style>
